home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / var / lib / dpkg / info / kdm.prerm < prev    next >
Text File  |  2008-10-24  |  6KB  |  176 lines

  1. #! /bin/sh
  2. # prerm script for kdm
  3. #
  4. # see: dh_installdeb(1)
  5.  
  6. set -e
  7.  
  8. # summary of how this script can be called:
  9. #        * <prerm> `remove'
  10. #        * <old-prerm> `upgrade' <new-version>
  11. #        * <new-prerm> `failed-upgrade' <old-version>
  12. #        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
  13. #        * <deconfigured's-prerm> `deconfigure' `in-favour'
  14. #          <package-being-installed> <version> `removing'
  15. #          <conflicting-package> <version>
  16. # for details, see http://www.debian.org/doc/debian-policy/ or
  17. # the debian-policy package
  18.  
  19. # debconf may not be available if some massive purging is going on
  20. HAVE_DEBCONF=
  21. if [ -e /usr/share/debconf/confmodule ]; then
  22.   . /usr/share/debconf/confmodule
  23.   HAVE_DEBCONF=yes
  24. fi
  25.  
  26. case "$1" in
  27.     # we NEVER want to unconditionally stop kdm; see below
  28.     upgrade|failed-upgrade)
  29.         REMOVING=
  30.     ;;
  31.  
  32.     remove|deconfigure)
  33.         REMOVING=yes
  34.     ;;
  35.  
  36.     *)
  37.         echo "prerm called with unknown argument \`$1'" >&2
  38.         exit 1
  39.     ;;
  40. esac
  41.  
  42. STOP=
  43. # are we supposed to restart on upgrade?  if REMOVING kdm, we don't care what
  44. # the user says, we have to stop the daemon
  45. if grep -qs ^restart-on-upgrade /etc/kde4/kdm/kdm.options ||
  46.    [ -n "$REMOVING" ]; then
  47.   # is there an kdm process running?
  48.   if start-stop-daemon --stop --quiet --signal 0 --name kdm; then
  49.     # any children?
  50.     PARENTS=$(pidof /usr/bin/kdm || true)
  51.     CHILDREN=
  52.     if [ -n "$PARENTS" ]; then    
  53.       for PROCESS in $PARENTS; do
  54.         # make sure we got numbers back
  55.         [ $PROCESS -eq $PROCESS ] 2> /dev/null ||
  56.         exit
  57.         # FIXME - redo this part uses shell-lib.sh from xfree86
  58.         #  die "pidof returned non-numeric value"
  59.         # we could use grep -q here if ps would ignore SIGPIPE :-P
  60.         if (ps axj | grep "^ *$PROCESS" > /dev/null 2>&1); then
  61.           CHILDREN=yes
  62.         fi
  63.       done
  64.       if [ -n "$CHILDREN" ]; then
  65.         if [ -n "$HAVE_DEBCONF" ]; then
  66.           # ask the question
  67.           db_input high kdm/stop_running_server_with_children || true
  68.           db_go
  69.           # what did the user say?
  70.           ANSWER=
  71.           if db_get kdm/stop_running_server_with_children; then
  72.             ANSWER="$RET"
  73.           fi
  74.           if [ "$ANSWER" = "true" ]; then
  75.             STOP=yes
  76.           fi
  77.           # forget that we have seen the question; this is the sort of
  78.           # non-configuration question that should be asked every time
  79.           db_fset kdm/stop_running_server_with_children seen false
  80.         fi
  81.       else
  82.         STOP=yes
  83.       fi
  84.     fi
  85.   fi
  86. fi
  87.  
  88. if [ -n "$STOP" ]; then
  89.   if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
  90.     invoke-rc.d kdm stop || true
  91.   else
  92.     /etc/init.d/kdm stop || true
  93.   fi
  94. else
  95.   if [ "$1" = "upgrade" -o "$1" = "failed-upgrade" ]; then
  96.     touch /var/run/kdm.upgrade
  97.   fi
  98. fi
  99.  
  100. DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
  101.  
  102. if [ "$1" = "remove" -o "$1" = "deconfigure" ]; then
  103.   if [ -n "$HAVE_DEBCONF" ]; then
  104.     # disown this question
  105.     db_unregister shared/default-x-display-manager || true
  106.     # does the question still exist?
  107.     if db_get shared/default-x-display-manager; then
  108.       if db_metaget shared/default-x-display-manager owners; then
  109.         # FIXME - redo this part uses shell-lib.sh from xfree86
  110.         #observe "X display managers now available are \"$OWNERS\""
  111.         db_subst shared/default-x-display-manager choices "$RET"
  112.       fi
  113.       DEFAULT_DISPLAY_MANAGER=
  114.       if db_get shared/default-x-display-manager; then
  115.         DEFAULT_DISPLAY_MANAGER="$RET"
  116.       fi
  117.       # are we removing the currently selected display manager?
  118.       if [ -n "$DEFAULT_DISPLAY_MANAGER" ]; then
  119.         if [ "kdm" = "$DEFAULT_DISPLAY_MANAGER" ]; then
  120.           if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
  121.             if db_get "$DEFAULT_DISPLAY_MANAGER/daemon_name"; then
  122.               # does the display manager file reference the current default?  if
  123.               # so, remove it because it will now be wrong
  124.               if [ -n "$RET" ]; then
  125.                 if [ "$(cat "$DEFAULT_DISPLAY_MANAGER_FILE")" = "$RET" ]; then
  126.                   rm "$DEFAULT_DISPLAY_MANAGER_FILE"
  127.                 fi
  128.               fi
  129.             fi
  130.           fi
  131.           # ask the user to choose a new default
  132.           db_fset shared/default-x-display-manager seen false
  133.           db_input critical shared/default-x-display-manager || true
  134.           db_go
  135.           # if the default display manager file doesn't exist, write it with
  136.           # the path to the new default display manager
  137.           if [ ! -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
  138.             DEFAULT_DISPLAY_MANAGER=
  139.             if db_get shared/default-x-display-manager; then
  140.               DEFAULT_DISPLAY_MANAGER="$RET"
  141.             fi
  142.             if [ -n "$DEFAULT_DISPLAY_MANAGER" ]; then
  143.               # FIXME - redo this part uses shell-lib.sh from xfree86
  144.               #warn "new default display manager has been selected; please be" \
  145.               #     "sure to run \"dpkg-reconfigure $RET\" to ensure that it" \
  146.               #     "is configured"
  147.               DAEMON_NAME=
  148.               if db_get "$DEFAULT_DISPLAY_MANAGER"/daemon_name; then
  149.                 DAEMON_NAME="$RET"
  150.               fi
  151.               if [ ! -n "$DAEMON_NAME" ]; then
  152.                 # if we were unable to determine the name of the selected daemon (for
  153.                 # instance, if the selected default display manager doesn't provide a
  154.                 # daemon_name question), guess
  155.                 DAEMON_NAME=$(which "$DEFAULT_DISPLAY_MANAGER" 2>/dev/null)
  156.                 if [ ! -n "$DAEMON_NAME" ]; then
  157.                   echo .
  158.                   # FIXME - redo this part uses shell-lib.sh from xfree86
  159.                   #warn "unable to determine path to default X display manager" \
  160.                   #     "$DEFAULT_DISPLAY_MANAGER; not updating" \
  161.                   #     "$DEFAULT_DISPLAY_MANAGER_FILE"
  162.                 fi
  163.               fi
  164.               if [ -n "$DAEMON_NAME" ]; then
  165.                 echo "$DAEMON_NAME" > "$DEFAULT_DISPLAY_MANAGER_FILE"
  166.               fi
  167.             fi
  168.           fi
  169.         fi
  170.       fi
  171.     fi
  172.   fi
  173. fi
  174.  
  175. exit 0
  176.